package com.wh.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wh.bean.MenuTree;
import com.wh.service.IMenuTreeService;
import com.wh.util.TreeNoteUtil;

/**
 * Description: 菜单树控制层 
 * @author hong.wei
 * Date 2016年9月7日 下午2:47:50
 * @version V1.0
 */
@Controller
@RequestMapping("menuTree")
public class MenuTreeController {

	private static final Logger LOGGER = LoggerFactory.getLogger(MenuTreeController.class);
	
	@Resource
	private IMenuTreeService service;
	
	@RequestMapping("/index/{view}")
	public ModelAndView index(@PathVariable("view") String view){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/" + view);
		return mv;
	}
	
	@RequestMapping(value = "selectMenuTrees")
	@ResponseBody
	public Object selectMenuTrees(){
		//用于把接收到的数据改造成EasyUI tree认识的数据格式
		List<MenuTree> menuTrees = new ArrayList<MenuTree>();
		try {
			//用于接收数据库查询到的数据
			List<MenuTree> list = service.selectMenuTrees(new MenuTree());
			menuTrees = TreeNoteUtil.getFatherNode(list);
		} catch (Exception e) {
			LOGGER.error("MenuTreeController.selectMenuTrees() error:" + e);
		}
		return menuTrees;
	}
}
